var reverse = function (x) {
    let res = 0
    let max = Math.pow(2, 31) - 1
    let min = max * -1
    while (x != 0) {
        let t = x % 10
        let newRes = res * 10 + t
        if (newRes > max || newRes < min) return 0
        res = newRes
        if (x > 0) x = Math.floor(x / 10)
        if (x < 0) x = Math.ceil(x / 10)
    }
    return res
};